var express = require('express');
var router = express.Router();
var tokenDao = require('./tokenDao');
var favorsDao = require('../dao/favors.dao');
router.get('/', (req, res) => {
    res.json({success:true});
});

// 增
router.post('/add', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }


    favorsDao.add(req.body, userId, res);

});

// 删
router.post('/delete', (req, res) => {
    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }


    favorsDao.del(req.body, userId, res);


});

// 改
router.post('/update', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }

    favorsDao.update(req.body, userId, res);

});

// 查
router.post('/find', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    // if (!req.body) {
    //     res.json({ success: false, info_massage: '缺少参数' });
    //     return;
    // }    
    console.log('-------------sd-d-d--d-d');

    console.log(userId);

    
    favorsDao.search(req.body, userId, res);

});
// 分页
router.post('/page', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }    

    favorsDao.page(req.body, userId, res);

});

module.exports = router;